//
//  THBaseButton.m
//  THImageEditDemo
//
//  Created by 希达 on 2018/3/29.
//  Copyright © 2018年 Tan.huang. All rights reserved.
//

#import "THBaseButton.h"

@interface THBaseButton ()

@property (assign, nonatomic) CGRect titleRect;
@property (assign, nonatomic) CGRect imageRect;

@end

@implementation THBaseButton

- (void)setType:(NSInteger)type {
    _type = type;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self setNeedsDisplay];
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    CGRect rect = [super titleRectForContentRect:contentRect];
    if (self.type == 1) {
        rect = CGRectMake(0, CGRectGetMaxY(self.imageRect) + 5, self.frame.size.width, rect.size.height);
    }
    self.titleRect = rect;
    return  rect;
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    CGRect rect = [super imageRectForContentRect:contentRect];
    if (self.type == 1) {
        CGFloat widht = self.frame.size.width * 0.5;
        rect = CGRectMake(self.frame.size.width * 0.5 - widht * 0.5, self.frame.size.height * 0.5 - widht * 0.5 - 10, widht, widht);
    }
    self.imageRect = rect;
    return rect;
}

@end



